from frame_work.setting import *
from frame_work.yaml_file import YAML
from frame_work.logger import Logger
from frame_work.login import PcLogin
from frame_work import menu_list
from frame_work.excel import get_all_data

logger = Logger(__name__).get_logger()


# 福利活动报名
class SubmitEnoll(object):

    def __init__(self):
        self.session = ''
        self.yaml = YAML(os.path.join(base_Dir, 'data', 'data.yaml'))

    @staticmethod
    def get_user_data(nums):
        """
        批量读取/data/buyer_data.xlsx试客账户，达到申请数量目的
        :param nums:
        :return:
        """
        data = get_all_data(nums)
        # 打乱user_data里边的数据
        # random.shuffle(data)
        # user_data = []
        # for uname in data:
        #     user_data.append(uname)
        return data

    def get_session(self,uname):
        """
        :return:返回登录用户session
        """
        login = PcLogin(uname)
        login.pc_login()
        return login.get_session()

    def submit_enoll(self, url, nums):
        """
        提交报名
        :return:
        """
        userdatas = SubmitEnoll.get_user_data(nums)
        for uname in userdatas:
            self.session = self.get_session(uname)
            r = self.session.get(url)
            print(r.text)


def main():
    report = SubmitEnoll()
    url = 'http://list.sk2.com/welfare/enroll'
    report.submit_enoll(url, 51)


if __name__ == "__main__":
    main()
